
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
	<meta charset="utf-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
	<meta name="viewport" content="width=device-width, initial-scale=1">
	<meta name="description" content="Responsive Admin Dashboard Template">
	<meta name="keywords" content="admin,dashboard">
	<meta name="author" content="skcats">
	<title>家庭联系信息</title>
	<link rel="stylesheet" th:href="@{/layui/css/layui.css}" media="all" />
	<style>
		.layui-table-page {
			text-align: center;
		}
		.layui-table {
			text-align: center;
			margin-top: -10px;
		}
		::-webkit-scrollbar {display:none}/*隐藏横向滚动条但可以滚动*/
		.layui-table-view thead th {
			text-align: center;
			font-weight: bold;
		}
		.layui-table-view tbody td {
			text-align: center;
		}
	</style>
<body>
<!--数据表格样式及附件-->
<script id="toolbar" type="text/html">
	<div class="layui-btn-container">
		<a onclick="javascript:history.back(-1);">
			<i class="layui-icon" style="font-size: 20px;padding-right: 10px;cursor: pointer;">&#xe65c;</i>
		</a>
		<span th:if="${session.user.emp_id == session.empid}">
			<button lay-event="add" class="layui-btn layui-btn-sm"><i class="layui-icon">&#xe654;</i>新增</button>
			<button lay-event="edit" class="layui-btn layui-btn-sm"><i class="layui-icon">&#xe642;</i>编辑</button>
			<button lay-event="delete" class="layui-btn layui-btn-sm"><i class="layui-icon">&#xe640;</i>删除</button>
		</span>
	</div>
</script>
<div>
	<!--    当前选择对象id-->
	<input type="hidden" id="id" th:value="${session.empid}">
</div>
<div class="utable">
	<table class="layui-table" id="worklist" lay-filter="worklist"></table>
</div>

</body>
<script th:src="@{/assets/plugins/jquery/jquery-3.1.0.min.js}"></script>
<script th:src="@{/layui/layui.js}"></script>
<script type="text/javascript" th:inline="none">
	layui.use('table', function () {
		var table = layui.table;
		var id = $('#id').val();
		//方法渲染
		table.render({
			elem: '#worklist'
			,id: 'tab'
			,height: 500
			,width: 1250
			,url: '/option/link?id='+id //数据接口
			,page: true //开启分页
			,toolbar: '#toolbar'
			,cols: [[ //表头
				{type: 'radio', title: '选择', fixed: 'left'}
				,{field: 'contactname', title: '联系人名称'}
				,{field: 'relationship', title: '与员工关系'}
				,{field: 'phone', title: '联系电话'}
				,{field: 'remark', title: '说明'}
			]]
		});

		table.on('toolbar(worklist)', function(obj){
			var checkStatus = table.checkStatus(obj.config.id);
			var data = checkStatus.data;
			var id = $.map(data,function(d){return d.familyid;});//获取选中数据的id
			if (obj.event === "add"){
				layer.open({
					type: 2,
					title: '新增',
					// maxmin: true, //开启最大化最小化按钮
					area: ['500px', '500px'],
					content: ['/option/tolinkadd']//这是链接你的页面地址 url
				});
			}else if (data.length === 0 && obj.event != 'LAYTABLE_COLS' && obj.event != 'LAYTABLE_EXPORT' && obj.event != 'LAYTABLE_PRINT'){
				layer.msg('请选择数据', { icon: 5, time: 2000 });
			}else if (obj.event === "delete"){
				layer.confirm('真的删除么?', function (index) {
					$.ajax({
						url: '/option/dellink?id='+id,
						type: 'post',
					})
					layer.close(index);
					$('.layui-laypage-btn').click();
				});
			}else if (obj.event === "edit"){
				layer.open({
					type: 2,
					title: '新增',
					// maxmin: true, //开启最大化最小化按钮
					area: ['500px', '500px'],
					content: ['/option/tolinkedit?id='+id]//这是链接你的页面地址 url
				});
			}
		});
	});
</script>
</html>
